/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tk.eigh.ksvg.types;

import java.util.logging.Logger;
import java.util.regex.Matcher;

/**
 *
 * @author nt
 */
public class SVGCoordinateEditor extends SVGLengthEditor {

    private SVGCoordinate _coordinate;

    @Override
    public Object getValue() {
        return _coordinate;
    }

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        Logger.getLogger(getClass().getName()).info(text);
        String trimmedValue = text.trim();
        Matcher matcher = PATTERN.matcher(trimmedValue);
        if (matcher.matches()) {
            SVGNumber number = new SVGNumber(matcher.group(1));
            if (matcher.group(2) != null) {
                this._coordinate = new SVGCoordinate(number, SVGUnits.valueOf(matcher.group(2).replace("%", "percent")));
            } else {
                this._coordinate = new SVGCoordinate(number);
            }
        } else {
            throw new IllegalArgumentException(SVGCoordinate.class.getName().concat(" must match pattern ").concat(PATTERN.pattern()));
        }
    }
}
